<?php
/**
 * 模块启动文件
 */
namespace addons\news;
use addons\news\controllers\index;
use system\Addon;

class News extends Addon {
    public function getName()
    {
        return 'news';
    }

    public function getVersion()
    {
        return '1.0.0';
    }

    public function getAuthor()
    {
        return 'Colin';
    }

    public function getDesc()
    {
        return '新闻组建';
    }

    public function install()
    {
		$sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@vote_news`(
id int unsigned not null auto_increment primary key , 
title varchar(200) not null comment '标题' , 
content text null comment '内容' , 
create_time int(10) default 0 comment '添加时间',
`views` int(10) DEFAULT '0' COMMENT '浏览数'
)engine=myisam charset=utf8 comment='投票记录';";
        return $sql;
    }

    public function uninstall()
    {
        $sql['1.0.0'][] = "DROP TABLE `@vote_news`;";
        return $sql;
    }

	public function onInitMenu(&$data = []){
		foreach ($data as $key => &$val){
			if ($val['name'] == 'vote'){
				$item = ['name' => 'list', 'title' => '新闻列表', 'auth_name' => index::class, 'action' => 'index' , 'jump' => '---news/index'];
				array_push($val['list'] , $item);
			}
		}
	}

	/**
	 * 依赖扩展
	 * @return array|string[]
	 * @author Colin <amcolin@126.com>
	 * @date 2022-02-08 下午9:52
	 */
	public function dependents() {
		return [
			'vote'
		];
	}
}